package com.mobilous.client.MainScreen;

import java.util.ArrayList;

import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.allen_sauer.gwt.dnd.client.drop.DropController;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.mobilous.client.StaticData;
import com.mobilous.client.project.ApplicationBuilder;
import com.mobilous.client.project.setup.SetupWizard;
import com.mobilous.client.tips.TipInterface;
import com.mobilous.client.tips.Tips;
import com.mobilous.client.tooltip.TooltipListener;

public class AppsList extends Composite implements TipInterface{
	CheckBox chckbxShowHints;
	public AppsList() {
		final AppsList self = this;
		AbsolutePanel absolutePanel = new AbsolutePanel();
		
		initWidget(absolutePanel);
		absolutePanel.setSize("1024px", "722px");
		
		final AbsolutePanel absolutePanelIcons = new AbsolutePanel();
		absolutePanel.add(absolutePanelIcons, 0, 0);
		absolutePanelIcons.setSize("950px", "722px");
		
		IconFile iconFile = new IconFile("images/appicon.png", "App One");
		absolutePanelIcons.add(iconFile, 10, 10);
		iconFile.setSize("77px", "86px");
	    
		TooltipListener image_PullDownTip = new TooltipListener("Click on Icon to edit App", 3000 ,"gwt-tooltip",iconFile);
		iconFile.addMouseOutHandler(image_PullDownTip);
		iconFile.addMouseOverHandler(image_PullDownTip);
		
		
		
		IconFile iconAddNew = new IconFile("images/appicon.png", "New App");
		absolutePanelIcons.add(iconAddNew, 93, 10);
		iconFile.setSize("77px", "86px");
		final ArrayList<String> tiplist = new ArrayList<String>();
		tiplist.add("Apps Page lets you create new apps as well as edit old ones.");
		tiplist.add("Apps can be published by dragging the app icon to publish button");
		tiplist.add("People are friends and colleagues who can participate in a project");
		tiplist.add("You can add People and assign them rights based on groups");
		tiplist.add("Freedom is the word, when there is nothing left to loose");
		tiplist.add("All the Jokers of the world unite and get drunk before WW3");
		absolutePanelIcons.add(new Tips(tiplist,self),0, 475);
		
		iconAddNew.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				StaticData.dialogSetupWizard = new SetupWizard();
				StaticData.dialogSetupWizard.setAnimationEnabled(true);
				StaticData.dialogSetupWizard.center();
				StaticData.dialogSetupWizard.show();
			}
		});
		
		
		chckbxShowHints = new CheckBox("Show Hints");
		absolutePanelIcons.add(chckbxShowHints, 0, 702);
		chckbxShowHints.setVisible(false);
		
		iconFile.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				new ApplicationBuilder();
			}
		});
		
		chckbxShowHints.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				chckbxShowHints.setVisible(false);
				chckbxShowHints.setValue(false);
				absolutePanelIcons.add(new Tips(tiplist,self),0, 475);
			}
		});
		
		PickupDragController dragController= new PickupDragController(absolutePanel, true);
		dragController.makeDraggable(iconFile);
		final AbsolutePanel absolutePanelMenu = new AbsolutePanel();
		absolutePanelMenu.setStyleName("gwt-background-SubMenu");
		absolutePanel.add(absolutePanelMenu, 956, 0);
		absolutePanelMenu.setSize("68px", "722px");
		IconFile cloneicon = new IconFile("images/copy.png", "Clone");
		absolutePanelMenu.add(cloneicon, 10, 10);
		IconFile publishicon = new IconFile("images/publish.png", "Publish");
		absolutePanelMenu.add(publishicon, 10, 86);
		ThrashIconFile thrashicon = new ThrashIconFile("images/recycle_bin.png", "Thrash");
		absolutePanelMenu.add(thrashicon, 10, 642);
		DropController closedTrashBinDropController = new BinDropController(thrashicon);
		
		Image imagein = new Image("images/bullet_arrow_in.png");
		absolutePanelMenu.add(imagein, 0, 344);
		imagein.setSize("32px", "32px");
		
		final Image imageout = new Image("images/bullet_arrow_out.png");
		absolutePanel.add(imageout, 992, 344);
		imageout.setSize("32px", "32px");
		imageout.setVisible(false);
		
		imagein.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				absolutePanelMenu.setVisible(false);
				imageout.setVisible(true);
			}
		});
		imageout.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				absolutePanelMenu.setVisible(true);
				imageout.setVisible(false);
			}
		});
		
		
		//dragController.set
		dragController.setBehaviorDragStartSensitivity(1);
	    dragController.registerDropController(closedTrashBinDropController);
	}

	@Override
	public void showCheckbox() {
		chckbxShowHints.setVisible(true);
	}
}
